// 采集汇总
<template>
    <!-- 拟招标内容明细 -->
    <div id="detailCon" >
        <div class="e-table">
                        <top-step :stepInfo="steps" />

            <div class="top">
                <div class="left">
                    <div>
                        <router-link to="/revolveCollectAdd">
                            <el-button
                                size="small"
                                style="background: #7aa818; color: #fff"
                                >新增</el-button
                            >
                        </router-link>
                    </div>
                </div>
                <div class="right">
                    <div class="right-div1">
                           <el-input placeholder="" size="small" v-model="pagination.keyWord"  @keydown.enter.native="fuzzySearchEnter" @blur="likeSearch">
                            <i slot="suffix" class="el-icon-search like" @click="likeSearch"></i>
                        </el-input>
                    </div>
                    <div>
                        <el-button
                            size="small"
                            style="background: #2e61d7; color: #fff"
                            >高级搜索</el-button
                        >
                    </div>
                </div>
            </div>
            <el-table
                class="table"
                :data="tableData"
                border
                style="width: 100%"
                ref="table"
                 v-sortTable="{ 'tableData': tableData, '_this': this, 'ref': 'table' }"

            >
                <!-- <el-table-column fixed label="操作" width="100">
                    <template slot-scope="scope">
                        <i
                            id="iconEdit"
                            style="
                                cursor: pointer;
                                font-size: 20px;
                            "
                            class="el-icon-edit"
                            @click="clickEdit(scope.row.billId)"
                        ></i>
                    </template>
                </el-table-column> -->
                <el-table-column fixed label="汇总编号" min-width="250" class-name="blue-column">
                    <template slot-scope="{row}">
                        <span @click="tableDbShow(row)">{{row.billNo}}</span>
                    </template>
                </el-table-column>

                <el-table-column prop="summaryDate" label="汇总日期" width="150">
                </el-table-column>
                <el-table-column
                    prop="amount"
                    label="计划金额（元）"
                    width="150"
                >
                </el-table-column>
                 <el-table-column
                    prop="state"
                    label="状态"
                    width="100"
                >
                    <template slot-scope="scope">
                    <ToolHistory v-if="scope.row.state == '1'" :key="scope.$index" url="/turnover/audit/getAuditHistory" :billId="scope.row.billId" :billType="6087">
                            <span   v-status="scope.row.state">
                                {{["草稿", "审核中", "已审核", "已关闭",'', "已作废"][scope.row.state]}}
                            </span>
                        </ToolHistory>
                        <span v-else  v-status="scope.row.state">
                            {{["草稿", "审核中", "已审核", "已关闭",'', "已作废"][scope.row.state]}}
                        </span>
                    </template>
                </el-table-column>
                 <el-table-column prop="orgName" label="机构" min-width="250">
                </el-table-column>
                <el-table-column label="来源" width="100">
                     <template slot-scope="{row}">
                        <span>{{ row.source==0?'主动增加':'自动生成' }}</span>
                    </template>
                </el-table-column>
            </el-table>
                 <ComPagination
            :total="pagination.total"
            :pageSize.sync="pagination.limit"
            :currentPage.sync="pagination.page"
            @currentChange="getTableData"
            @sizeChange="getTableData"
            :class="{ bottomSetting }"
        />
        </div>
    </div>
</template>
<script>
import ComPagination from '@/components/pagination/pagination'
import { vueDom, debounce } from '@/utils/common.js'
import TopStep from '@/components/topstep/topstep.vue'
import auditRequest from '@/api/turnover/audit.js'

export default {
    components: {
        ComPagination, TopStep
    },

    data () {
        return {
            tableData: [],
            pagination: {
                limit: 20,
                number: '',
                orgname: '',
                page: 1,
                'keyWord': '',
            },
            bottomSetting: true,
            MouseEnterId: 0,
            stateArr: ['草稿', '审核中', '已审核', '已作废'],
            tableHeight: 0,
            fn: null,
            steps: [
                {
                    description: '年度需用计划',
                    http: '/yearNeedPlan'
                },
                {
                    description: '采集汇总',
                    http: '/revolveCollectList'

                },
            ],
            auditParams: {
                billId: this.$route.query.billid,
                billType: 6087,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            },
        }
    },
    computed: {
        statusLable () {
            return param => {
                const state = this.$store.state.equip.equipData.state
                const obj = state.find(x => x.value == param)
                if (obj !== undefined) {
                    return obj.label
                }
            }
        },

    },
    created () {
        this.getTableData()
    },
    mounted () {
        // table动态高度
        vueDom(
            () => {
                this.tableHeight = document.body.clientHeight - 240
            },
            () => {
                return $('table').length !== 0
            }
        )
        this.fn = () => {
            this.tableHeight = document.body.clientHeight - 240
        }
        window.onresize = debounce(this.fn)
    },
    methods: {
        getTableData () {
            this.$Ajax
                .httpPost({
                    url: '/turnover/centralizedPurchaseSummary/listByEntity',
                    params: this.pagination
                })
                .then(res => {
                    this.tableData = res.list
                    this.pagination.total = res.totalCount

                })
        },
        //回车键查询
        fuzzySearchEnter (e) {
            if(e.keyCode == 13) {
                this.getTableData()
            }
        },
        //模糊查询
        likeSearch () {
            this.getTableData()
        },
        //点击进入查看页面
        tableDbShow (row) {
            const billid = row.billId
            // this.$router.push({
            //     path: '/revolveCollectShow',
            //     query: { billid }
            // })
            if(row.state === -1 || row.state === 2 || row.state === 5) {
                this.$router.push({
                    path: '/revolveCollectShow',
                    query: { billid }
                })
            }else{
                this.auditParams.billId = row.billId
                // 根据按钮状态来判断点击编辑进什么页面
                auditRequest.getCurrentUnitInfo(this.auditParams).then(res => {
                    this.auditState = res
                    if( this.auditState.canModify) {
                        this.$router.push({
                            path: '/revolveCollectEdit',
                            query: { billid }
                        })
                    }else{
                        this.$router.push({
                            path: '/revolveCollectShow',
                            query: { billid }
                        })
                    }
                })

            }
        },

        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        //点击查看的时候
        clickEdit (id) {
            this.$router.push({ path: '/revolveCollectEdit', query: { billid: id } })
        }
    }
}
</script>
<style lang="scss" scoped>
#iconEdit:hover {
    color: red;
}
</style>
